package com.luoran.system.service.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.luoran.system.domain.TradesmanCity;
import com.luoran.system.mapper.TradesmanCityMapper;
import com.luoran.system.service.TradesmanCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TradesmanCityServiceImpl implements TradesmanCityService{

    @Autowired
    TradesmanCityMapper tradesmanCityMapper;

    public List<TradesmanCity> selectCity(){
        return tradesmanCityMapper.selectCity();
    }

    @Override
    public List<Tree<Object>> selectDataCity() {
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        treeNodeConfig.setIdKey("id");
        treeNodeConfig.setNameKey("cityName");
        treeNodeConfig.setDeep(4);
        treeNodeConfig.setParentIdKey("parentId");
        treeNodeConfig.setChildrenKey("children");
        List<TradesmanCity> city = selectCity();
        List<Tree<Object>> build = TreeUtil.build(city, 1, treeNodeConfig, (treeNode, tree) -> {
            tree.setId(treeNode.getId());
            tree.setName(treeNode.getCityName());
            tree.setParentId(treeNode.getPid());
            // 设置其他属性
            tree.putExtra("type", treeNode.getType());
        });
        return build;
    }


    //extends ServiceImpl<TradesmanCityMapper, TradesmanCity> implements TradesmanCityService
}




